home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Un ejercicio de presentación de texto / SysInfoPanel / SysInfoPanel.cs next >
Encoding:
Text File  |  2002-05-22  |  1.9 KB  |  58 lines

  1. //-------------------------------------------
  2. // SysInfoPanel.cs ⌐ 2001 by Charles Petzold
  3. //-------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class SysInfoPanel: Form
  9. {
  10.      readonly float cxCol;
  11.      readonly int   cySpace;
  12.  
  13.      public static void Main()
  14.      {
  15.           Application.Run(new SysInfoPanel());
  16.      }
  17.      public SysInfoPanel()
  18.      {
  19.           Text = "Informaci≤n del Sistema: Panel";
  20.           BackColor = SystemColors.Window;
  21.           ForeColor = SystemColors.WindowText;
  22.           AutoScroll = true;
  23.  
  24.           Graphics grfx  = CreateGraphics();
  25.           SizeF    sizef = grfx.MeasureString(" ", Font);
  26.           cxCol   = sizef.Width + SysInfoStrings.MaxLabelWidth(grfx, Font);
  27.           cySpace = Font.Height;
  28.  
  29.                // Creaci≤n de un panel.
  30.  
  31.           Panel panel    = new Panel();
  32.           panel.Parent   = this;
  33.           panel.Paint   += new PaintEventHandler(PanelOnPaint);
  34.           panel.Location = Point.Empty;
  35.           panel.Size     = new Size(
  36.               (int) Math.Ceiling(cxCol + 
  37.                                  SysInfoStrings.MaxValueWidth(grfx, Font)),
  38.               (int) Math.Ceiling(cySpace * SysInfoStrings.Count));
  39.           grfx.Dispose();
  40.      }
  41.      void PanelOnPaint(object obj, PaintEventArgs pea)
  42.      {
  43.           Graphics grfx       = pea.Graphics;
  44.           Brush    brush      = new SolidBrush(ForeColor);
  45.           int      iCount     = SysInfoStrings.Count;
  46.           string[] astrLabels = SysInfoStrings.Labels;
  47.           string[] astrValues = SysInfoStrings.Values;
  48.  
  49.           for (int i = 0; i < iCount; i++)
  50.           {
  51.                grfx.DrawString(astrLabels[i], Font, brush, 
  52.                                0, i * cySpace);
  53.                grfx.DrawString(astrValues[i], Font, brush, 
  54.                                cxCol, i * cySpace);
  55.           }
  56.      }
  57. }
  58.